﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Text;
using System.IO.IsolatedStorage;
using System.Diagnostics;

namespace ControlHost
{
    public partial class MainPage : PhoneApplicationPage
    {
        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
        
        //public TcpSocket tcpSock;
        public UdpSocket udpSock;
        public string strHost;
        public int nPort;

        // 构造函数
        public MainPage()
        {
            InitializeComponent();
            InitSettings();
        }

        private void InitSettings()
        {
            if (settings.Contains("Host"))
            {
                strHost = (string)settings["Host"];
            }
            else
            {
                strHost = "192.168.1.102";
                settings.Add("Host", strHost);
            }

            if (settings.Contains("Port"))
            {
                nPort = (int)settings["Port"];
            }
            else
            {
                nPort = 11000;
                settings.Add("Port", nPort);
            }

            (Application.Current as App).strHost = strHost;
            (Application.Current as App).nPort = nPort;

        }


        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            //tcpSock = (Application.Current as App).tcpSock;
            udpSock = (Application.Current as App).udpSock;
            strHost = (Application.Current as App).strHost;
            nPort = (Application.Current as App).nPort;

            base.OnNavigatedTo(e);
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/SettingPage.xaml", UriKind.Relative));
        }

        private void btnTouchPad_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/MousePage.xaml", UriKind.Relative));
        }

        private void btnKeyBoard_Click(object sender, RoutedEventArgs e)
        {

        }

    }
}